﻿using SalesPortal.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace SalesPortal.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult Context()
        {
            ViewBag.Message = "Your current/change context  page.";

            return View();
        }

        public ActionResult Dice(string id)
        {
            //ViewBag.Message = "Your current/change context  page." + id.ToString();

            //System.Security.Cryptography.
            //Random r = new Random();
            

            //for (int i = 0; i < 1000; i++)
            //{
            //    current_number = r.Next(id);
            //    if (current_number == 0)
            //        sb.AppendLine(string.Format("{0},", id));
            //    else
            //        sb.AppendLine(string.Format("{0},", current_number));
            //}

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            ViewBag.Message = sb.ToString();

            // Parse id into dice notation (ie 2d6)
            Regex reDice = new Regex(@"^(?<num>\d+)?[dD]?(?<side>\d+)?$"); // Regex for dice notation

            Match m = GameHelper.DiceNotationRegEx.Match(id);

            if (!m.Success)
            {
                ViewBag.Message = "Invalid dice notation";
                return View();
            }

            int number_of_iterations = 1000;

            for (int i = 0; i < number_of_iterations; i++)
            {
                int current_number = GameHelper.Dice(id);
                sb.AppendLine(string.Format("{0},", current_number));
            }

            ViewBag.Message = sb.ToString();
            return View();
        }


        /// <summary>
        /// Task list for user
        /// </summary>
        /// <returns></returns>
        public ActionResult Task()
        {
            ViewBag.Message = "Task list for user page.";

            return View();
        }
    }
}